package com.matt.domain;

import com.matt.commons.exception.BusinessException;
import com.matt.commons.model.Domain;

import com.matt.foundation.model.ErrorCode;
import com.matt.foundation.utils.ModelUtil;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.persistence.*;
import java.util.Date;

/**
 * *******************************
 * Created by Ron.
 * form com.matt
 * on 2017/7/6
 * *******************************
 */
@Table(name = "classes", uniqueConstraints = {@UniqueConstraint(columnNames = {"name", "areaId"})})
@Entity
@Data
@EqualsAndHashCode(callSuper=true)
public class Classes extends Domain {

    @Column(columnDefinition = "varchar(50) COMMENT '班级名称'")
    private String name;

    @Column(columnDefinition = "int default 0 COMMENT '满额学生数量'")
    private Integer limitNum;

    /**
     * 消课规则
     */
    @Column(columnDefinition = "int default 0 COMMENT '扣除规则'")
    private Integer deleteNum;

    /**
     * 到课删除（0否，1是）
     */
    @Column(columnDefinition = "int default 0 COMMENT '到课删除'")
    private Integer deleteClass;
    /**
     * 请假删除（0否，1是）
     */
    @Column(columnDefinition = "int default 0 COMMENT '请假删除'")
    private Integer deleteLeave;
    /**
     * 缺勤删除（0否，1是）
     */
    @Column(columnDefinition = "int default 0 COMMENT '缺勤删除'")
    private Integer deleteAbsence;

    /**
     * 主班老师id
     */
    @ApiModelProperty(value = "主班老师id")
    private String staffId;

    /**
     * 主班老师
     */
    @ApiModelProperty(value = "主班老师")
    private String staffName;

    /**
     * 配班老师id
     */
    @ApiModelProperty(value = "配班老师id")
    private String fitStaffId;
    /**
     * 配班老师
     */
    @ApiModelProperty(value = "配班老师")
    private String fitStaffName;

    /**
     * 保育老师id
     */
    @ApiModelProperty(value = "保育老师id")
    private String careStaffId;
    /**
     * 保育老师
     */
    @ApiModelProperty(value = "保育老师")
    private String careStaffName;

    @Column(columnDefinition = "int default 0 COMMENT '开始月份'")
    private Integer beginMonth;

    @Column(columnDefinition = "int default 0 COMMENT '结束月份'")
    private Integer endMonth;

    @Column(columnDefinition = "varchar(32) COMMENT '适用对象id'")
    private String targetObjectId;

    @Column(columnDefinition = "varchar(32) COMMENT '序号'")
    private String orderNumber;

    @Column(columnDefinition = "varchar(32) COMMENT '园区id'")
    private String areaId;

    @Column(columnDefinition = "int default 1  COMMENT '班级类型 1,托班，2，早教'")
    private Integer category;

    @Column(columnDefinition = "varchar(100) COMMENT '备注信息'")
    private String remark;

    @Column(columnDefinition = "varchar(100) COMMENT '班主任名称'")
    private String inChargeTeacherName;

    @Column(columnDefinition = "varchar(32) COMMENT ' 班主任id'")
    private String inChargeTeacherId;

    @Column(columnDefinition = "datetime COMMENT '基础日期'")
    private Date baseTime;

    public Classes merge(Classes classes) {
        try {
            ModelUtil.copyNotNullPropertiesExcludeId(this, classes);
        } catch (Exception e) {
            throw new BusinessException(ErrorCode.ENTITY_MERGE_ERROR, "拷贝属性出错");
        }
        return this;
    }
}
